<%--
  Created by IntelliJ IDEA.
  User: 34662
  Date: 2023/6/23
  Time: 15:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <!-- 引入 layui.css -->
    <link href="https://cdn.staticfile.org/layui/2.7.6/css/layui.css" rel="stylesheet">

    <!-- 引入 layui.js -->
    <script src="//unpkg.com/layui@2.6.8/dist/layui.js"></script>
</head>
<style>
    #addForm{
        margin-left: 20px;
    }
    .layui-input, .layui-textarea{
        width: 300px;
    }
</style>
<body>
<div><b>计划表</b></div>
<table id="demo" lay-filter="test"></table>

<div><b>生产表</b></div>
<table id="demo2" lay-filter="test"></table>
<div id="addForm" style="display: none;">
    <table>
        <tr><td>
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    订单
                    <input type="text" disabled name="quotationNumber" required  lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    款号
                    <input type="text" disabled name="styleNumberId" required  lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    商品
                    <input type="text" disabled name="productDetailId" required  lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    尺寸
                    <input type="text" name="size" disabled   lay-verify="required"required  autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    尺寸测量
                    <input type="text" name="measurement" disabled   lay-verify="required"required  autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    品牌
                    <input type="text" name="brand" disabled   lay-verify="required"required  autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    交货地址
                    <input type="text" name="deliveryAddress" disabled   lay-verify="required"required  autocomplete="off" class="layui-input">
                </div>
            </div>
        </td></tr>

    </table>
</div>
</body>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-sm" lay-event="produce">生产</a>
    <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="detail">详情</a>
</script>
<script>
    var selectOption = null;
    layui.use('table', function(){
        var table = layui.table;
        //第一个实例
        table.render({
            elem: '#demo'
            ,height: 270
            ,url: 'sewingManager/getAllPlanDepartmentSize' //数据接口
            ,page: true //开启分页
            , limit: 5
            , limits: [5, 10, 15]
            ,cols: [[ //表头
                {field: 'productionPlanId', title: 'ID', width:100, sort: true, fixed: 'left'},
                {field: 'quotationNumber', title: '订单编号', width:150, sort: true, fixed: 'left'}
                ,{field: 'orderMoney', title: '订单金额', width:100}
                ,{field: 'staffDepartment', title: '部门', width:80}
                ,{field: 'schedeleCount', title: '计划生产的数量', width:130}
                ,{field: 'name', title: '尺寸', width:80}
                ,{field: '', title: '操作', width: 140,toolbar: "#barDemo"}
            ]]
        });

        table.render({
            elem: '#demo2'
            ,height: 270
            ,url: 'sewingManager/queryAllSubmission' //数据接口
            ,page: true //开启分页
            , limit: 5
            , limits: [5, 10, 15]
            ,cols: [[ //表头
                {field: 'quotationNumber', title: '订单编号', width:150, sort: true, fixed: 'left'}
                ,{field: 'productionPlanId', title: '计划生产', width:150, sort: true, fixed: 'left'}
                ,{field: 'staffDepartment', title: '部门', width:80}
                ,{field: 'producedCount', title: '生产的数量', width:130}
                ,{field: 'name', title: '尺寸', width:80}
                ,{field: 'productName', title: '商品名称', width:130}
                ,{field: 'styleNumber', title: '款号', width:130}
                ,{field: 'submitDate', title: '提交时间', width:130}
            ]]
        });

        table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data;
            console.log(data)
            if(obj.event === 'detail'){ //详情
                $('[name=quotationNumber]').val(data.quotationNumber);
                $('[name=styleNumberId]').val(data.styleName);
                $('[name=productDetailId]').val(data.productName);
                $('[name=size]').val(data.name);
                $('[name=brand]').val(data.brand);
                $('[name=deliveryAddress]').val(data.deliveryAddress);
                $('[name=measurement]').val(data.measurement);
                layer.open({
                    title: '订单详情',
                    type:1,
                    area: ['50%', '80%'], // 弹窗大小
                    content: $("#addForm"),
                    btn: ['确认', '取消'],
                    yes: function(index, layero){
                        layer.close(index); // 关闭弹窗
                    },
                    btn2: function(index, layero){
                        layer.close(index);
                    }
                });
            }else if (obj.event === 'produce'){
                // console.log(obj.data)
                var params = new URLSearchParams();
                params.append('data', JSON.stringify(data)); // 将data对象转换为JSON字符串并添加到URL参数中
                var url = 'toAddSewing?' + params.toString(); // 拼接URL参数
                layer.open({
                    title: '添加记录',
                    type:2,
                    area: ['50%', '80%'], // 弹窗大小
                    content: url,
                    btn: ['确认', '取消'],
                    yes: function(index, layero){
                        location.reload();
                        layer.close(index); // 关闭弹窗
                    },
                    btn2: function(index, layero){
                        layer.close(index);
                    }
                });
            }
        });
    });
    // 定义回调函数，处理选中的值
    function handleSelectOption(selectedValue) {
        // 在这里执行你希望执行的方法或代码 //
        // 例如，调用一个名为 `doSomething()` 的方法
        alert(selectedValue);
    }
</script>

</html>
